﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using COMOSOFT.Class;
using COMOSOFT.MatarialManagement.Forms;
using DevExpress.XtraNavBar;

namespace COMOSOFT.MatarialManagement.Forms
{
    public partial class FrmConfirmCons : Form
    {
        int MALID;
        FrmStyleDetails frmStD = null;
        string StatusCons,Comment;
        ClassShare cls = new ClassShare("FrmConfirmCons");
        public FrmConfirmCons()
        {
            InitializeComponent();
        }

        public void LoadData(string Status)
        {
            sp_MAConfirmConsTableAdapter.Fill(dataSetMatarial.sp_MAConfirmCons,ClassShare.Usid,Status);
        }

        private void gridView_ConfirmCons_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                GridView view = sender as GridView;
                if (!view.IsGroupRow(view.FocusedRowHandle))
                {
                    MALID = Convert.ToInt32(view.GetFocusedDataRow()["MALID"]);
                    frmStD = new FrmStyleDetails(MALID);
                    frmStD.MdiParent = this;
                    frmStD.LoadData();
                    frmStD.Text = "TrimList No: " + view.GetFocusedDataRow()["MALNo"].ToString();
                    frmStD.Show();
                    frmStD.RunBackroundWorker();
                    navBarControl_ConfirmCons.OptionsNavPane.NavPaneState = NavPaneState.Collapsed;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #region[Change Load Data]
        private void radio_ConfirmCons_SelectedIndexChanged(object sender, EventArgs e)
        {           
            switch (radio_ConfirmCons.SelectedIndex)
            {
                case 0:
                    StatusCons="Waiting";
                    break;
                case 1:
                    StatusCons = "Approved";
                    break;
                case 2:
                    StatusCons = "Reject";
                    break;
            }
            LoadData(StatusCons);
        }
        #endregion

        #region[CofirmCons]
        private void ConfirmToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dockPanel_Confirm.Show();
        }    

        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadData("Waiting");
        }        

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region[FormLoad]
        private void FrmConfirmCons_Load(object sender, EventArgs e)
        {          
            dockPanel_Confirm.Close();
        }
        #endregion

        #region[Update Confirm]

        private void bnt_Cancel_Click(object sender, EventArgs e)
        {
            dockPanel_Confirm.Close();
        }

        private void bnt_OK_Click(object sender, EventArgs e)
        {
            try
            {
                if (radio_ConfirmCons.SelectedIndex == 0)
                    StatusCons = "Approved";
                else
                    StatusCons = "Reject";
                Comment = txt_Comment.Text;
                cls.UpdateData("sp_TrimListUpdateStatus", new string[] { "@MALID", "@StatusCons","@Comment" }, new object[] { MALID, StatusCons, Comment });
                dockPanel_Confirm.Close();
                MessageBox.Show("Approve successfully!");
                LoadData("Waiting");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        #endregion
    }
}
